﻿<form>
    @Html.AntiForgeryToken()
    <div style="margin:0 auto; text-align:center; padding-top:28px;">
        <div>
            <img src="~/RoadFlowResources/images/loading/load1.gif" alt="" />
        </div>
        <div style="margin-top:5px;">
            @ViewData["msg"]
        </div>
    </div>
</form>
<script type="text/javascript">
    var op = "@ViewData["op"]";
    var openerid = '@ViewData["openerid"]';
    var frame = null;
    $(function ()
    {
        var iframes = top.frames;
        for (var i = 0; i < iframes.length; i++)
        {
            var fname = "";
            try
            {
                fname = iframes[i].name;
            }
            catch (e)
            {
                fname = "";
            }
            if (fname == openerid + "_iframe")
            {
                frame = iframes[i];
                break;
            }
        }
        if (frame == null)
        {
            frame = top.roadflowCurrentWindow;
        }
        if (frame == null) return;
        switch (op)
        {
            case "save":
                save();
                break;
            case "install":
                install();
                break;
            case "uninstall":
                uninstall(2);
                break;
            case "delete":
                uninstall(3);
                break;
        }
    });

    function save()
    {
        var json = JSON.stringify(frame.wf_json);
        $.ajax({
            url: "Save?appid=@ViewData["appId"]", type: "post", async: true, dataType: "text",
            data: { json: json, "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val() },
            success: function (txt)
            {
                if ("1" == txt)
                {
                    alert("保存成功!");
                } else
                {
                    alert(txt);
                }
                window.setTimeout('new RoadUI.Window().close();', 1);
            }, error: function (obj)
            {
                alert(obj.responseText);
                window.setTimeout('new RoadUI.Window().close();', 1);
            }
        });
    }
    function install() {
        var json = JSON.stringify(frame.wf_json);
        $.ajax({
            url: "Install?appid=@ViewData["appId"]", type: "post", async: true, dataType: "text",
            data: { json: json, "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val() },
            success: function (txt)
            {
                if (1 == txt) {
                    alert("安装成功!");
                } else {
                    alert(txt);
                }
                window.setTimeout('new RoadUI.Window().close();', 1);
            }, error: function (obj) { alert(obj.responseText); window.setTimeout('new RoadUI.Window().close();', 1); }
        });
    }
    function uninstall(status) {
        var json = frame.wf_json;
        $.ajax({
            url: "UnInstall?appid=@ViewData["appId"]", type: "post", async: true, dataType: "text",
            data: { flowid: json.id, status: status, "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val() },
            success: function (txt)
            {
                if ("1" == txt) {
                    alert((status == 2 ? "卸载" : "删除") + "成功!");
                } else {
                    alert(txt);
                }
                window.setTimeout('new RoadUI.Window().close();', 1);
            }, error: function (obj) { alert(obj.responseText); window.setTimeout('new RoadUI.Window().close();', 1); }
        });
    }
</script>